typedef struct ListNode ListNode;
ListNode* deleteDuplicates(ListNode* head)
{
    if (head == NULL || head->next == NULL)
    {
        return head;
    }
    ListNode* prev = NULL;
    ListNode* cur = head;
    ListNode* next = cur->next;
    while (next)
    {
        if (cur->val != next->val)
        {
            prev = cur;
            cur = next;
            next = next->next;
        }
        else
        {
            while (next && cur->val == next->val)
            {
                next = next->next;
            }
            if (prev)
            {
                prev->next = next;
            }
            else
            {
                head = next;
            }
            //释放空间
            ListNode* del = NULL;
            while (cur != next)
            {
                del = cur->next;
                free(cur);
                cur = del;
            }
            if (next)
            {
                cur = next;
                next = next->next;
            }
            else {
                prev->next;
            }
        }
    }
    return head;
}